from PyQt5.QtCore import pyqtSignal
from PyQt5.QtWidgets import QVBoxLayout, QPushButton, QWidget, QTabWidget, QHBoxLayout, QLabel, QLineEdit, QSpacerItem, QSizePolicy

from componnents.BoxInfo import BoxInfo
from componnents.PlatInfo import PlatInfo


class PlatformIssues(QWidget):
    passAddressSignal = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        vLaout = QVBoxLayout()
        hLayout = QHBoxLayout()
        label = QLabel("输入中台ip:")
        self.centerIpAddress = QLineEdit()
        self.centerIpAddress.setFixedWidth(200)
        confirmIpBtn = QPushButton("确定")
        hLayout.addWidget(label)
        hLayout.addWidget(self.centerIpAddress)
        hLayout.addWidget(confirmIpBtn)
        confirmIpBtn.clicked.connect(self.passAddress)
        spacer = QSpacerItem(200, 20, QSizePolicy.Expanding, QSizePolicy.Minimum)
        hLayout.addSpacerItem(spacer)
        tabWidget = QTabWidget()
        tab1 = PlatInfo()
        tab2 = BoxInfo()
        # 将三个tab加入主窗口，并且将名字设为如下
        tabWidget.addTab(tab1, "中台信息")
        tabWidget.addTab(tab2, "纳管设备信息")
        self.passAddressSignal.connect(tab1.showPlatInfo)
        vLaout.addLayout(hLayout)
        vLaout.addWidget(tabWidget)
        self.setLayout(vLaout)

    def passAddress(self):
        ipAddress = self.centerIpAddress.text()
        self.passAddressSignal.emit(ipAddress)
